package com.keyinong.caizhengting.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.keyinong.caizhengting.R;
import com.keyinong.caizhengting.tools.HttpTools;
import com.keyinong.caizhengting.entity.HongbaoEntity;

import java.util.ArrayList;

/**
 * 红包
 */

public class HongbaoAdapter extends BaseAdapter {
    Context context;
    ArrayList<HongbaoEntity> hongbaoList;
    HttpTools httpTools = null;

    public HongbaoAdapter(Context context, ArrayList<HongbaoEntity> hongbaoList) {
        super();
        this.context = context;
        this.hongbaoList = hongbaoList;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return hongbaoList.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return hongbaoList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        final ViewHandle handle;
        if (view == null) {
            handle = new ViewHandle();
            view = LayoutInflater.from(context).inflate(R.layout.item_hongbao, null);
            handle.tv_off = (TextView) view.findViewById(R.id.tv_off);
            handle.tv_more = (TextView) view.findViewById(R.id.tv_more);
            handle.tv_starttime = (TextView) view.findViewById(R.id.tv_starttime);
            handle.tv_endtime = (TextView) view.findViewById(R.id.tv_endtime);
            handle.tv_note = (TextView) view.findViewById(R.id.tv_note);
            view.setTag(handle);
        } else {
            handle = (ViewHandle) view.getTag();
        }

        handle.tv_more.setText("满" + hongbaoList.get(position).getMore());
        handle.tv_off.setText("减" + hongbaoList.get(position).getOff());
        handle.tv_starttime.setText(hongbaoList.get(position).getStarttime());
        handle.tv_endtime.setText(hongbaoList.get(position).getEndtime());
        handle.tv_note.setText(hongbaoList.get(position).getNote());
        return view;
    }

    class ViewHandle {
        /**
         * 限制金额
         */
        TextView tv_more;
        /**
         * 红包金额
         */
        TextView tv_off;
        /**
         * 使用起始时间
         */
        TextView tv_starttime;
        /**
         * 使用截止时间
         */
        TextView tv_endtime;
        /**
         * note
         */
        TextView tv_note;
    }
}
